var mongo_module = require("./dbmgr")
var http = require("http")
var { App, AsyncInitServer} = require("./netmgr")


async function InitDB() {
    var res = await mongo_module.ConnectDB()
    if (!res) {
        console.log("mongo client connected failed")
        return res
    }
    return res
}


(async function () {
    var init_res = await InitDB()
    if (!init_res) {
        console.log("init db failed")
        return
    }
    var server = await AsyncInitServer()
    if (!server) {
        console.log("server init failed")
        return
    }
    console.log("server init success")
    process.on('SIGINT', async function () {
        console.log('Exit now!');
        await server.close();
        await mongo_module.DisconnectDB()
        process.exit();
    });
})()



